﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Extensil.Common.CategoryHandler.Discovery
{
    public class DiscoveryResultList : List<DiscoveryResult>
    {
        public static DiscoveryResultList Convert(List<DiscoveryResult> results)
        {
            DiscoveryResultList retValue = new DiscoveryResultList();
            foreach(DiscoveryResult dr in results)
                retValue.Add(dr.Copy);
            return retValue;
        }
        public void Remove(string name)
        {
            foreach(DiscoveryResult dr in this)
            {
                if(dr.Name.ToLower() == name.ToLower())
                {
                    this.Remove(dr);
                    return;
                }
            }
        }
        public DiscoveryResult Get(string name)
        {
            foreach(DiscoveryResult dr in this)
            {
                if(dr.Name.ToLower() == name.ToLower())
                {
                    return dr.Copy;
                }
            }
            return null;
        }
    }

    public class DiscoveryResult
    {
        public BaseProbeHandler ProbeHandler
        {
            get;
            set;
        }
        public string Name
        {
            get;
            set;
        }
        public string Description
        {
            get;
            set;
        }
        public Version Version
        {
            get;
            set;
        }
        public DateTime ModifiedOn
        {
            get;
            set;
        }
        public string Link
        {
            get;
            set;
        }
        public bool AutoUpdate
        {
            get;
            set;
        }

        public DiscoveryResult() : this("", new Version(), DateTime.Now, "")
        {
        }
        public DiscoveryResult(string name, Version version, DateTime modDate, string link) :
            this(name, version, modDate, link, "")
        {
        }
        public DiscoveryResult(string name, Version version, DateTime modDate, string link, string desc):
               this(name, version, modDate, link, "", false)
        {
        }
        public DiscoveryResult(string name, Version version, DateTime modDate, string link, string desc, bool autoUpdate)
        {
            Name = name;
            Version = version;
            ModifiedOn = modDate;
            Link = link;
            Description = desc;
            AutoUpdate = autoUpdate;
        }

        public DiscoveryResult Copy
        {
            get
            {
                DiscoveryResult dr = new DiscoveryResult(Name, Version, ModifiedOn, Link, Description, AutoUpdate);
                dr.ProbeHandler = this.ProbeHandler;
                return dr;
            }
        }
    }
}
